<?php

class CC_Helpdesk_Rule_BasicRegex extends CC_Helpdesk_Rule_Abstract
{
    public function parse()
    {
        // @TODO: Ensure that method exists
        // Get the source to compare apply rule on
        $methodName = 'get'.ucfirst($this->_ruleExpressions['field']);
        $source = $this->_ticket->$methodName();
        
        switch($this->_ruleExpressions['matchType'])
        {
            case 'equal':
                $pattern = '/\b'.$this->_ruleExpressions['value'].'\b/i';
                break;
            case 'like':
                $pattern = '/'.$this->_ruleExpressions['value'].'/i';
                break;
            case 'custom':
                $pattern = $this->_ruleExpressions['value'];
                break;
        }
        
        preg_match($pattern, $source, $matches);
        
        if(count($matches))
            return true;
        
        return false;
    }
}
?>